package dataInit

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gowork/viewExamineNode/model"
	"time"
)

type MysqlInit struct {

}

var (
	Db *gorm.DB
	err error
)

func init() {
	dsn := "root:new_password@tcp(127.0.0.1:3306)/view_examine_node?charset=utf8mb4&parseTime=True&loc=Local"
	Db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil{
		panic("db error")
	}

	sqlDb, pErr := Db.DB()
	if pErr != nil{
		panic("db error")
	}
	sqlDb.SetMaxIdleConns(10)
	sqlDb.SetMaxOpenConns(100)
	sqlDb.SetConnMaxLifetime(time.Hour)

	Db.AutoMigrate(&model.CheckNode{}, &model.Region{}, &model.User{}, &model.CheckNodeUser{})
}

